package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.AddReportService;
import com.yixun.qfbao.model.enums.SystemIdEnum;
import com.yixun.qfbao.util.WxAccessTokenCacheUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.CPReportService;
import com.yixun.qfbao.apidto.ReportAgainReqDto;
import com.yixun.qfbao.apidto.ReportAgainResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.ReportAgainReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * 重新发起报备
 * @author JHSong
 *
 */
@Service("reportAgainHander")
public class ReportAgainHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(ReportAgainHander.class);
	
	@Autowired
	private AddReportService addReportService;
	@Autowired
    private WxAccessTokenCacheUtils wxAccessTokenCacheUtils;
	
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		ReportAgainReqVo req = (ReportAgainReqVo)reqDto;
		ReportAgainReqDto reqDto1 = req.getParams();
		BaseResponseDTO<ReportAgainResDto> res = new BaseResponseDTO<ReportAgainResDto>();
		ReportAgainResDto resDto = new ReportAgainResDto();
		try {
            //获取案场助手的微信accessToken
            String assistantAccessToken = wxAccessTokenCacheUtils.getAccessToken(reqDto1.getCompanyUuid(), SystemIdEnum.ASSISTANT.getCode(), reqDto1.getDomain());
			resDto = addReportService.reportAgain(reqDto1, assistantAccessToken);
		}catch(TServerException e){
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg(e.getErrorMsg());
		} catch (Exception e) {
			logger.error("ReportAgainHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("系统异常");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
